<template>
	<el-container>
		<el-container>
			<el-header>
				<div class="right-panel">
					<div class="right-panel-search">
						<el-input v-model="search.end_price" placeholder="搜索单号/产品名称" clearable></el-input>
						<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
						<el-button type="info" @click="refresh">重置</el-button>
					</div>
				</div>
				<div class="left-panel">
					<el-button type="danger" :disabled="selection.length == 0" @click="batch_del" v-auth="'spare.deleteAll'">撤回</el-button>
				</div>
			</el-header>
			<el-main class="nopadding">
				<scTable @row-dblclick="dblclick" ref="table" :apiObj="apiObj" row-key="id"  @selection-change="selectionChange" stripe remoteSort remoteFilter border :params="query">
					<el-table-column fixed="left" type="selection" width="50" reserve-selection></el-table-column>
					<el-table-column label="操作" fixed="left" align="center" width="130">
						<template #default="scope">
							<el-button-group>
                                <el-popconfirm title="确定执行吗？" @confirm="table_work(scope.row, scope.$index)">
                                    <template #reference>
								        <el-button text type="primary" size="small">执行</el-button>
                                    </template>
                                </el-popconfirm>
                                <el-popconfirm title="确定撤回吗？" @confirm="table_withdraw(scope.row, scope.$index)">
                                    <template #reference>
								        <el-button text type="danger" size="small">撤回</el-button>
                                    </template>
                                </el-popconfirm>
							</el-button-group>
						</template>
					</el-table-column>
					<el-table-column label="单据编号" prop="customAddress"></el-table-column>
					<el-table-column label="审核状态" prop="customAddress"></el-table-column>
					<el-table-column label="单据日期" prop="customAddress"></el-table-column>
					<el-table-column label="生产加工单号" prop="customAddress" width="120"></el-table-column>
                    <el-table-column label="工序状态" prop="work.status" align="center">
                        <template #default="scope">
                            <el-tag :type="scope.row.work.status == 0 ? 'success' : 'danger'">{{scope.row.work.status == 0 ?'启用':'禁用'}}</el-tag>
                        </template>
                    </el-table-column>
					<el-table-column label="是否委外" prop="work.is_out" align="center">
                        <template #default="scope">
                            <el-tag :type="scope.row.work.is_out == 1 ? 'success' : 'danger'">{{scope.row.work.is_out == 1 ?'是':'否'}}</el-tag>
                        </template>
                    </el-table-column>
					<el-table-column label="报工权限" prop="work.work_power" align="center">
                        <template #default="scope">
                            <!-- {{scope.row.work.dept}} {{scope.row.work.admin}} -->
                            {{scope.row.work.work_power == 1 ? '班组' : '人员'}}
                        </template>
                    </el-table-column>
					<el-table-column label="工艺文件" prop="customAddress" align="center">
                        <template #default="scope">
                            <el-button text size="small" type="primary" @click="showFile(scope.row.work.enclosure)">查看附件</el-button>
                        </template>
                    </el-table-column>
					<el-table-column label="工艺路线" prop="route.route_name" align="center"></el-table-column>
					<el-table-column label="物料编码" prop="product.goods_code" align="center" width="100"></el-table-column>
					<el-table-column label="物料名称" prop="product.goods_name" align="center" width="100"></el-table-column>
					<el-table-column label="物料类别" prop="product.cate_name" align="center"></el-table-column>
					<el-table-column label="规格型号" prop="product.goods_spec" align="center"></el-table-column>
					<el-table-column label="计划开工日期" prop="machin.plan_start" align="center" width="120"></el-table-column>
					<el-table-column label="计划完工日期" prop="machin.plan_end" align="center" width="120"></el-table-column>
					<el-table-column label="工序名称" prop="work.work_name" align="center"></el-table-column>
					<el-table-column label="产出比例" prop="route_detail.match" align="center"></el-table-column>
					<el-table-column label="加工说明" prop="route_detail.maching" align="center"></el-table-column>
					<el-table-column label="操作工" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="时间单位" prop="route_detail.time_unit" align="center"></el-table-column>
					<el-table-column label="标准工时" prop="route_detail.standard_time" align="center"></el-table-column>
					<el-table-column label="标准总工时" prop="customAddress" align="center" width="120"></el-table-column>
					<!-- <el-table-column label="工序计划数量" prop="customAddress" align="center"></el-table-column> -->
                    <el-table-column label="良品数" prop="customAddress" align="center">
                        <template #default="scope">
                            {{ (scope.row.machin&&scope.row.machin.number * Number(scope.row.route_detail&&scope.row.route_detail.match)) - scope.row.rejects_num }}
                        </template>
                    </el-table-column>
					<el-table-column label="不良品数" prop="rejects_num" align="center"></el-table-column>
					<el-table-column label="变更原因" prop="turn_reason"></el-table-column>
					<el-table-column label="变更人" prop="turn_staff"></el-table-column>
					<!-- <el-table-column label="工序成本" prop="customAddress"></el-table-column> -->
					<el-table-column label="变更日期" prop="turn_date"></el-table-column>
					<el-table-column label="是否末道工序" prop="customAddress" align="center" width="120">
                        <template #default="scope">
                            <el-tag :type="scope.row.route_detail&&scope.row.route_detail.is_last == 1 ? 'success' : 'danger'">{{scope.row.route_detail&&scope.row.route_detail.is_last == 1 ?'是':'否'}}</el-tag>
                        </template>
                    </el-table-column>
					<el-table-column label="是否检验" prop="customAddress" align="center">
                        <template #default="scope">
                            <el-tag :type="scope.row.work&&scope.row.work.is_quality == 1 ? 'success' : 'danger'">{{scope.row.work&&scope.row.work.is_quality == 1 ?'是':'否'}}</el-tag>
                        </template>
                    </el-table-column>
					<!-- <el-table-column label="变更次数" prop="customAddress"></el-table-column> -->
					<el-table-column label="单位计时工资" prop="customAddress" width="120"></el-table-column>
					<el-table-column label="单位计件工资" prop="customAddress" width="120"></el-table-column>
					<el-table-column label="完工状态" prop="customAddress"></el-table-column>
				</scTable>
			</el-main>
		</el-container>
	</el-container>
</template>

<script>
export default {
	name: 'user',
	components: {
	},
	data() {
		return {
			dialog: {
				save: false,
			},
			group: [],
			apiObj: this.$API.production.processplan.list,
			selection: [],
			search: {
				title: null,
				cid: null,
			},
            query:{
                is_turn:2
            }
		}
	},
	methods: {
        // 报工
		async table_work(row) {
            var reqData = {id: row.id,turn_status:2,staff:row.staff}
			var res = await this.$API.production.turn.post(reqData);
			if (res.code == 1) {
				this.$refs.table.refresh();
				this.$message.success("操作成功")
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
        // 撤回
		async table_withdraw(row) {
            var reqData = {id: row.id,turn_status:3,staff:row.staff}
			var res = await this.$API.production.turn.post(reqData);
			if (res.code == 1) {
				this.$refs.table.refresh();
				this.$message.success("操作成功")
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//删除
		async table_del(row, index) {
			var reqData = {id: row.id}
			var res = await this.$API.basicdata.applyList.delete.post(reqData);
			if (res.code == 1) {
				//这里选择刷新整个表格 OR 插入/编辑现有表格数据
				this.$refs.table.tableData.splice(index, 1);
				this.$refs.table.refresh();
				this.$message.success("删除成功")
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
		selectionChange(selection) {
			this.selection = selection;
		},
	}
}
</script>

<style>
.search-input {
	width: auto;
	font-size: 14px;
}

.shopInfo {
	display: flex;
	align-items: center;
}

.img {
	width: 100px;
	height: 100px;
	margin-right: 5px;
}
</style>
